package cn.sytton.taffecloud.service.file.controller;

import cn.sytton.taffecloud.common.base.doc.Api;
import cn.sytton.taffecloud.common.base.doc.ApiImplicitParam;
import cn.sytton.taffecloud.common.base.doc.ApiOperation;
import cn.sytton.taffecloud.common.base.doc.ParamType;
import cn.sytton.taffecloud.common.model.file.FileEntity;
import cn.sytton.taffecloud.service.file.constants.FileBucket;
import cn.sytton.taffecloud.service.file.service.IFileService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;

/**
 * 临时文件服务控制层
 *
 * @author skyrock
 */
@Api(tags = "临时文件")
@RestController
@RequestMapping("/temp")
public class FileTempController {

    @Resource
    private IFileService fileService;

    @ApiOperation("下载临时文件")
    @ApiImplicitParam(name = "object", value = "存储对象名", paramType = ParamType.query)
    @GetMapping
    public void download(String objectName) {
        fileService.downloadObject(objectName, FileBucket.TEMP);
    }

    @ApiOperation("上传临时文件")
    @ApiImplicitParam(name = "file", value = "文件", paramType = ParamType.body, dataTypeClass = MultipartFile.class)
    @PostMapping
    public FileEntity upload(@RequestBody File file) {
        return fileService.upload(file, FileBucket.TEMP);
    }
}
